package com.zhengtoudai.http;

import android.util.Log;

import com.zhengtoudai.base.App;
import com.zhengtoudai.util.Tool;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 缓存拦截器
 */

public class CacheControlInterceptor implements Interceptor {


    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder request = chain.request().newBuilder();
        if (App.mApp.hasLogin()) {
            request.addHeader("JSESSIONID", App.mApp.getSession().get("JSESSIONID"));
            request.addHeader("token", App.mApp.getSession().get("token"));
        }
        request.addHeader("deviceId", Tool.getAppId(App.getContext()))
                .addHeader("User-Agent", "android")
                .addHeader("randomCode", Tool.getCharAndNumr(10));
        Log.e("header", request.build().toString());
        return chain.proceed(request.build());

    }
}
